﻿using Microsoft.CSharp.Activities;
using System;
using System.Activities;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WFExtended.Twitter.Activities.Designers;

namespace WFExtended.Twitter.Activities
{
    /// <summary>
    /// Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values 
    /// passed to the usernames parameters.
    /// </summary>
    [ToolboxBitmapAttribute(typeof(EntryPoint), "Resources.UsersToolbox.bmp")]
    [Designer(typeof(UsersDesigner))]
    [Description("Returns fully-hydrated user objects for up to 100 users per request.")]
    public class UsersLookup : TwitterOperationInvoker<List<User>>
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="UsersLookup"/> class.
        /// </summary>
        public UsersLookup()
            : base("UsersLookup")
        {
            IncludeEntities = new InArgument<bool>(new CSharpValue<bool>("true"));
        }


        /// <summary>
        /// A comma separated list of screen names, up to 100 are allowed in a single request. 
        /// <remarks>
        /// Required Argument
        /// </remarks>
        /// </summary>
        /// <value>
        /// The usernames.
        /// </value>
        [Browsable(true)]
        [Category("Properties")]
        [RequiredArgument]
        [Description("A comma separated list of screen names, up to 100 are allowed in a single request. ")]
        public InArgument<string> Usernames { get; set; }

        /// <summary>
        /// The entities node will be omitted when set to false.
        /// </summary>
        /// <value>
        /// The include entities.
        /// </value>
        [Browsable(true)]
        [Category("Properties")]
        [RequiredArgument]
        [Description("The entities node will be omitted when set to false.")]
        public InArgument<bool> IncludeEntities { get; set; }

        /// <summary>
        /// Caches the metadata.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        protected override void CacheMetadata(System.Activities.NativeActivityMetadata metadata)
        {
            RuntimeArgument usernamesArgument = new RuntimeArgument("Usernames", typeof(string), ArgumentDirection.In, true);
            metadata.Bind(Usernames, usernamesArgument);
            metadata.AddArgument(usernamesArgument);

            RuntimeArgument includeEntitiesArgument = new RuntimeArgument("IncludeEntities", typeof(bool), ArgumentDirection.In, true);
            metadata.Bind(IncludeEntities, includeEntitiesArgument);
            metadata.AddArgument(includeEntitiesArgument);

            base.CacheMetadata(metadata);
        }

        /// <summary>
        /// Executes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected override void Execute(System.Activities.NativeActivityContext context)
        {
            Parameters.Clear();

            Parameters.Add("usernames", Usernames);
            Parameters.Add("includeEntities", IncludeEntities);

            base.Execute(context);
        }
    }
}
